<?php

/**
* ValidationRule.class.php
*
* Validation rules used in forms
*
* @author     Blazej Zieba <b@zieba.info>
* @copyright  2007 konekto.com
* @version    CVS: $Id:$
*/

require_once("MimeType.class.php");


function numericOrNull($elementValue)
{
    
    if ( is_numeric($elementValue) )
    {
        return true;
    }

    if ( !isset($elementValue) )
    {
        return true;
    }
    
    return false;
} 

function myRuleCheckMimeType($elementValue,$validType = '' )
{

    if ( $validType == '' )
    {
        return false;
    }

    if (!HTML_QuickForm_file::_ruleIsUploadedFile($elementValue)) {
        return false;
    }

    $mt = new MimeType();
    $currentType = $mt->get($elementValue['name']);

    if ( PEAR::isError($currentType) ) 
    {
        return false;
    }

    return stristr($currentType, $validType); 
} 


HTML_QuickForm::registerRule('NumericOrNull','callback','numericOrNull');
HTML_QuickForm::registerRule('mymimetype', 'callback', 'myRuleCheckMimeType');

?>
